package com.lsh.oms.core.enums;

import com.lsh.base.common.exception.BusinessException;
import com.lsh.base.common.model.CommonResult;

public enum EC {
	ERROR(CommonResult.ERROR, "error"),
	SEND_REQUEST_ERROR("E3000", "发送请求失败"),
	ERROR_PARAMS("E0000", "请求参数错误！"),
	DATA_IS_NULL("E0001", "系统数据为空！"),
	GOODS_IS_ERROR("E2200", "商品信息错误！"),
	STATUS_NOT_OPERATE("E0002", "当前状态不允许操作"),
	UPDATE_DATA_FAIL("E0003", "当前状态不允许操作"),
	UPDATE_NO_ORDER("E0005", "订单信息不存在"),
	UPDATE_DB_ERROR("E0006", "操作数据库错误"),
	SYSTEM_CALL_FAIL("E0004", "系统调用失败");


	private final String code;

	private final String message;

	EC(String code, String message) {
		this.code = code;
		this.message = message;
	}

	public String getCode() {
		return code;
	}

	public String getMessage() {
		return message;
	}

	public BusinessException exception() {
		return new BusinessException(this.getCode(), this.getMessage());
	}

	public BusinessException exception(String message) {
		return new BusinessException(this.getCode(), new StringBuilder(this.message).append("\n").append(message).toString());
	}

	public BusinessException exception(Throwable e) {
		return new BusinessException(this.getCode(), new StringBuilder(this.message).append("\n").append(e.getMessage()).toString(), e);
	}
}
